package cn.wolfcode.sendcode.controller;

import cn.wolfcode.sendcode.domain.Sms;
import com.github.qcloudsms.SmsSingleSender;
import com.github.qcloudsms.SmsSingleSenderResult;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class SmsController {

    @PostMapping("/sendCode")
    public void sms(@RequestBody Sms sms){
        int appid=1400330563;
        String appkey="ef1e3d4f939cdf086c096be552920371";
        int templateId=308731;
        String smsSign="CNXFS";
        try {
            String[] params= {sms.getCode(),Integer.toString(sms.getMin())};
            SmsSingleSender ssender = new SmsSingleSender(appid, appkey);
            SmsSingleSenderResult result = ssender.sendWithParam("86", sms.getPhoneNum(), templateId, params, smsSign, "", "");
            System.out.println(result);

        }catch (Exception e){
            e.printStackTrace();
        }

    }
}
